﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RPGMapa.Data;

namespace RPGMapa.Forms
{
    public partial class OpenTileset : Form
    {
        public OpenTileset()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Bitmap tileSet;
            OpenFileDialog open = new OpenFileDialog();
            try
            {
                open.Filter = "Image Files(*.png; *.jpg; *.jpeg; *.gif; *.bmp)|*.png; *.jpg; *.jpeg; *.gif; *.bmp";
                if (open.ShowDialog() == DialogResult.OK)
                {
                    tileSet = new Bitmap(open.FileName);
                    textBox1.Text = open.FileName;
                }
            }
            catch
            {
                MessageBox.Show("Esse arquivo não é um arquivo de imagem válido.");
            }
            finally
            {
                open.Dispose();
            }
        }

        public ImgMatrix Result()
        {
            try
            {
                return new ImgMatrix(new Bitmap(textBox1.Text), (int)numericUpDown1.Value, (int)numericUpDown2.Value);
            }
            catch
            {
                return null;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Hide();
            this.textBox1.Text = ""; // forces result to return null;
            this.Close();
        }
    }
}
